﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据视图 V_PLM_CP_ProductCompare 对应的数据应用功能类。
	/// </summary>
	public class V_PLM_CX_ProductCompareApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IV_PLM_CX_ProductCompareRepository service = new V_PLM_CX_ProductCompareRepository();

        public List<V_PLM_CX_ProductCompareEntity> GetList(Pagination pagination, string number, string type)
        {
            var expression = ExtLinq.True<V_PLM_CX_ProductCompareEntity>();
            //expression = expression.And(t => t.UseUnit == UseUnit);
            string where = string.Format("[UseUnit]='{0}' AND [ZDH] like '%{1}%'", UseUnit, number);
            if (type == "差别件")
            {
                where += " AND SL1<>SL2";
            }
            else if (type == "相同件")
            {
                where += " AND SL1=SL2";
            }
            return service.FindList(expression, pagination, where);
        }

        public void SetStampingContrastResult(string number1, string number2)
        {
            service.ExecSql(string.Format("exec PROC_PLM_CP_ProductCompare '{0}','{1}'", number1, number2));
        }

        public V_PLM_CX_ProductCompareEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
    }
}